package com.wing.cabinet.controller.admin;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.cabinet.model.entity.Cabinet;
import com.wing.cabinet.model.entity.CellInventoryInout;
import com.wing.cabinet.model.response.CellInventoryInoutVO;
import com.wing.cabinet.service.CellInventoryInoutService;
import com.wing.common.utils.PageResult;
import com.wing.web.utils.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 领新记录（新）
 * @author
 */
@Slf4j
@Validated
@Api(value = "Admin-领新记录（新）", tags = "#/cabinet/cellInventoryOutNew")
@RestController("cellInventoryOutNewController")
@RequestMapping("cabinet/admin/cellInventoryOutNew")
@RequiredArgsConstructor
public class CellInventoryOutNewController {

    private final CellInventoryInoutService cellInventoryInoutService;

    @ApiOperation(value = "领新记录(新)", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "code", value = "领新订单编号", defaultValue = "", example = "", dataType = "String", paramType = "query")
    })
    @GetMapping("/list")
    public PageResult<CellInventoryInoutVO> list(
            @RequestParam(defaultValue = "1") Integer page
            , @RequestParam(defaultValue = "10") Integer limit
            , @RequestParam(defaultValue = "create_time") String sort
            , @RequestParam(defaultValue = "desc") String order
            , String code
            , String cabCode
            , String skuCode
            , String skuCode4Detail
            , String startTime
            , String endTime
            , String deviceCode
            , String oldSpecCode
            , String mainCabCode
            , Cabinet.CabinetNature cabinetNature
            ,Long departmentId
            ,Long creatorId
            ,Long brandId
            ,Long categoryId
            ,Long productId
            ,Long roleId
            ,String skuCode4Query
            ,String deviceCode4Query
            ,Long packId
            ,String workOrderCode
            ,CellInventoryInout.BusinessType businessType
            ,String skuName
            ){

        Page<CellInventoryInout> pg = new Page<>(page, limit);
        Map queryParam=new HashMap();
        queryParam.put("sort",StrUtil.toUnderlineCase(sort));
        queryParam.put("order",order);
        queryParam.put("code",code);
        queryParam.put("cabCode",cabCode);
        queryParam.put("skuCode",skuCode);
        queryParam.put("exportType",1);
        queryParam.put("skuCode4Detail",skuCode4Detail);
        queryParam.put("startCreateTime",startTime);
        queryParam.put("endCreateTime",endTime);
        queryParam.put("deviceCode",deviceCode);
        queryParam.put("oldSpecCode",oldSpecCode);
        queryParam.put("mainCabCode",mainCabCode);
        queryParam.put("skuName",skuName);
        if (cabinetNature!=null){
            queryParam.put("cabinetNature",cabinetNature.getValue());
        }
        if (businessType!=null){
            queryParam.put("businessType",businessType.getValue());
        }
        queryParam.put("enterpriseCode", JwtUtils.getEnterpriseCode());
        queryParam.put("departmentId",departmentId);
        queryParam.put("creator",creatorId);
        queryParam.put("brandId",brandId);
        queryParam.put("categoryId",categoryId);
        queryParam.put("productId",productId);
        queryParam.put("roleId",roleId);
        queryParam.put("oldSpecCode",oldSpecCode);
        queryParam.put("skuCode4Query",skuCode4Query);
        queryParam.put("deviceCode4Query",deviceCode4Query);
        queryParam.put("packId",packId);
        queryParam.put("workOrderCode",workOrderCode);

        IPage<CellInventoryInoutVO> list = cellInventoryInoutService.pageListNew(pg,queryParam);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }

}
